home *** CD-ROM | disk | FTP | other *** search
- Path: oxy.rust.net!usenet
- From: ebennett@rust.net
- Newsgroups: comp.lang.c++
- Subject: Re: Visual C++ 4.0 lacking initializers?
- Date: Fri, 26 Jan 1996 19:12:49 GMT
- Organization: Rust Net - High Speed Internet in Detroit 810-642-2276
- Message-ID: <4eauhh$47v@oxy.rust.net>
- References: <31049C46.A26@oz.is>
- NNTP-Posting-Host: liv-3.rust.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hßlfdan Ingvarsson <halfdan@oz.is> wrote:
-
- >Is it me or is this sort of code not possible with VC++ 4.0?
-
- >// Declarations of class Foo
-
- >// VC++ Complains about the line below with the error
- >// error C2436: '__ctor' : cannot initialize member functions
- >Foo::Foo(void) : Foo::Foo(10) {}
-
- >Foo::Foo(x)
- >{
- > // Some stuff
- >}
-
- Here is yet another way to do this that I did not think of when I
- posted my first response to this. What this is really attempting to
- mimmick is a constructor with a default parameter.
-
- class Foo
- {
- public:
- Foo (int x = 10);
- ....
- };
-
- Foo::Foo (int x)
- {
- // do initialization
- };
-
- This results in the following:
-
- Foo a; // a is initialized with the value 10
- Foo b(5); // b is initialized with the value 5
-
- Earl
-
-
-